


function SignIn_functions_isUserNameExit() {
    SignIn_$username.change(function () {
        $.post(
            UserUrl+"/isUserNameExit",
            {"username":SignIn_$username.val()},
            function (data) {
                SignIn_isUserExit=data["data"];
                if(SignIn_isUserExit){
                    alert("用户名已存在,请重新输入");
                    SignIn_$username.val("");
                }
            },
            "json"
        )
    })

}


function  SignIn_functions_fllPage() {
    SignIn_$breadcrumbs.find("a").get(0).href=FilmUrl+common_index;

}

function  SignIn_functions_passwordDifference() {
        SignIn_$password_again.change(
            function () {
                let password_again = $(this).val();
                if(password_again!==undefined&&password_again!==""){
                    let password = SignIn_$password.val();
                    if(password!==password_again){
                        alert("两次输入密码不一致");
                        SignIn_passwordDifference=false;
                        SignIn_$password_again.val("");
                    }else {
                        SignIn_passwordDifference=true;
                    }
                }
            }
        )
}

function  SignIn_functions_clickSignIn() {
    SignIn_$SignIn.click(
        function () {
            let $String ="";
            $String= SignIn_functions_checkInputSize($String);
           $String= SignIn_functions_checkEmail($String);
           $String=SignIn_functions_checkPictLength($String);
           $String=SignIn_functions_checkPassword($String);
           if($String!==""){
               SignIn_$form.get(0).action="#";
               alert($String);
               return  false;
           }
           SignIn_$form.get(0).action=UserUrl+"signIn";
         Cookies.set("UserName",SignIn_$username.val());
         Cookies.set("password",SignIn_$password.val());
           alert("欢迎您注册");
            return true;
        }
    )
}


function  SignIn_functions_checkInputSize($String) {

        let $username = SignIn_$username.val();
        let $password = SignIn_$password.val();

        if($username===""||$username.length>SignIn_$username.get(0).alt){
            $String+="用户名长度不符合要求\n";
        }
        if($password===""||$password.length>SignIn_$password.get(0).alt){
            $String+="密码长度不符合要求\n";
        }
        return $String;
}
function SignIn_functions_checkPassword($String) {
    if(!SignIn_passwordDifference){
        $String+="两次密码不一致\n";
    }

    return $String;
}

function SignIn_functions_checkEmail($String){
    let $email = SignIn_$email.val();
    if($email!==""&&!reg.exec($email)){
        $String+="邮箱格式错误\n";
    }
    return $String;
}
function SignIn_functions_checkPictLength($String) {
        if(!SignIn_pictLength){
            $String+="图片格式或尺寸错误\n";
        }
        return $String;
}
function SignIn_functions_main() {
    SignIn_functions_fllPage();
    new SignIn_functions_passwordDifference();
   new SignIn_functions_isUserNameExit();
    SignIn_functions_clickSignIn();
    SignIn_functions_pictLength();
}


function SignIn_functions_pictLength() {
    let w=870;
    let h=518;
    let type="JPEG JPG PNG";
    $("#headPhoto").change(function () {
        SignIn_pictLength=false;
        let file = $(this).val().toUpperCase();

        if(file===""){
            SignIn_pictLength=true;

        }else if(type.indexOf(file.substring(file.lastIndexOf(".")+1))===-1) {
            SignIn_pictLength=false;

        } else{
            let MyTest = document.getElementById("headPhoto").files[0];
            let reader = new FileReader();
            reader.readAsDataURL(MyTest);
            reader.onload = function (theFile) {
                let image = new Image();
                image.src = theFile.target.result;
                image.onload = function () {
                    // alert("图片的宽度为"+this.width+",长度为"+this.height);
                    let width = image.width;
                    let height = image.height;
                    SignIn_pictLength = w <= width && h <= height;

                };
            };
        }


    })

}